<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能作息规划应用 - ERNIE+智源</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            color: #333;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
        }
        
        .header {
            text-align: center;
            color: white;
            margin-bottom: 30px;
        }
        
        .header h1 {
            font-size: 2.5em;
            margin-bottom: 10px;
        }
        
        .header p {
            font-size: 1.2em;
            opacity: 0.9;
        }
        
        .main-content {
            background: white;
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        }
        
        .form-section {
            margin-bottom: 30px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #555;
        }
        
        .form-group input, .form-group select {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        
        .form-group input:focus, .form-group select:focus {
            outline: none;
            border-color: #667eea;
        }
        
        .btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 15px 30px;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            cursor: pointer;
            transition: transform 0.2s;
        }
        
        .btn:hover {
            transform: translateY(-2px);
        }
        
        .schedule-result {
            margin-top: 30px;
            display: none;
        }
        
        .schedule-card {
            background: #f8f9fa;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
        }
        
        .schedule-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px;
            background: white;
            border-radius: 8px;
            margin-bottom: 10px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        
        .time-slot {
            font-weight: bold;
            color: #667eea;
            min-width: 120px;
        }
        
        .activity {
            flex: 1;
            margin: 0 15px;
        }
        
        .priority {
            padding: 5px 10px;
            border-radius: 15px;
            font-size: 12px;
            font-weight: bold;
        }
        
        .priority.高 { background: #ff6b6b; color: white; }
        .priority.中 { background: #feca57; color: white; }
        .priority.低 { background: #48dbfb; color: white; }
        .priority.最高 { background: #ff3838; color: white; }
        
        .tips-section {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-top: 30px;
        }
        
        .tip-card {
            background: #f8f9fa;
            border-radius: 10px;
            padding: 20px;
        }
        
        .tip-card h3 {
            color: #667eea;
            margin-bottom: 15px;
        }
        
        .tip-card ul {
            list-style: none;
        }
        
        .tip-card li {
            padding: 8px 0;
            border-bottom: 1px solid #eee;
        }
        
        .tip-card li:last-child {
            border-bottom: none;
        }
        
        .loading {
            text-align: center;
            padding: 20px;
            display: none;
        }
        
        .spinner {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #667eea;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto 20px;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .footer {
            text-align: center;
            color: white;
            margin-top: 30px;
            opacity: 0.8;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🤖 智能作息规划应用</h1>
            <p>基于ERNIE-4.5-0.3B模型 + 智源Infinity-Instruct数据集</p>
            <p>GitCode&文心大模型&智源研究院AI应用开发大赛作品</p>
        </div>
        
        <div class="main-content">
            <div class="form-section">
                <h2>📝 个人信息设置</h2>
                <form id="scheduleForm">
                    <div class="form-group">
                        <label for="name">姓名：</label>
                        <input type="text" id="name" name="name" placeholder="请输入您的姓名" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="wake_time">起床时间：</label>
                        <input type="time" id="wake_time" name="wake_time" value="07:00" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="sleep_time">睡觉时间：</label>
                        <input type="time" id="sleep_time" name="sleep_time" value="23:00" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="work_type">工作类型：</label>
                        <select id="work_type" name="work_type" required>
                            <option value="创意工作">创意工作</option>
                            <option value="分析工作">分析工作</option>
                            <option value="沟通协调">沟通协调</option>
                            <option value="学习培训">学习培训</option>
                            <option value="体力劳动">体力劳动</option>
                        </select>
                    </div>
                    
                    <button type="submit" class="btn">🚀 生成智能作息规划</button>
                </form>
            </div>
            
            <div class="loading" id="loading">
                <div class="spinner"></div>
                <p>AI正在为您生成个性化作息规划...</p>
            </div>
            
            <div class="schedule-result" id="scheduleResult">
                <h2>📅 您的个性化作息规划</h2>
                <div class="schedule-card">
                    <h3>⏰ 每日时间安排</h3>
                    <div id="dailyPlan"></div>
                </div>
                
                <div class="tips-section">
                    <div class="tip-card">
                        <h3>💡 健康建议</h3>
                        <ul id="healthTips"></ul>
                    </div>
                    
                    <div class="tip-card">
                        <h3>⚡ 效率提升</h3>
                        <ul id="productivityTips"></ul>
                    </div>
                    
                    <div class="tip-card">
                        <h3>🤖 AI洞察</h3>
                        <ul id="aiInsights"></ul>
                    </div>
                    
                    <div class="tip-card">
                        <h3>🎯 本周目标</h3>
                        <ul id="weeklyGoals"></ul>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="footer">
            <p>Powered by ERNIE-4.5-0.3B-Paddle & 智源Infinity-Instruct</p>
            <p>© 2024 智能作息规划应用 - AI应用开发大赛作品</p>
        </div>
    </div>

    <script>
        document.getElementById('scheduleForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            // 显示加载状态
            document.getElementById('loading').style.display = 'block';
            document.getElementById('scheduleResult').style.display = 'none';
            
            // 收集表单数据
            const formData = new FormData(this);
            const userData = Object.fromEntries(formData);
            
            try {
                // 发送请求到后端
                const response = await fetch('/api/generate_schedule', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify(userData)
                });
                
                const result = await response.json();
                
                if (result.success) {
                    displaySchedule(result.schedule);
                } else {
                    alert('生成失败：' + result.message);
                }
            } catch (error) {
                console.error('Error:', error);
                alert('网络错误，请稍后重试');
            } finally {
                document.getElementById('loading').style.display = 'none';
            }
        });
        
        function displaySchedule(schedule) {
            // 显示每日计划
            const dailyPlan = document.getElementById('dailyPlan');
            dailyPlan.innerHTML = '';
            
            schedule.daily_plan.forEach(item => {
                const scheduleItem = document.createElement('div');
                scheduleItem.className = 'schedule-item';
                scheduleItem.innerHTML = `
                    <div class="time-slot">${item.time}</div>
                    <div class="activity">
                        <strong>${item.activity}</strong>
                        <br><small>${item.tips}</small>
                    </div>
                    <div class="priority ${item.priority}">${item.priority}</div>
                `;
                dailyPlan.appendChild(scheduleItem);
            });
            
            // 显示健康建议
            const healthTips = document.getElementById('healthTips');
            healthTips.innerHTML = '';
            schedule.health_tips.forEach(tip => {
                const li = document.createElement('li');
                li.textContent = tip;
                healthTips.appendChild(li);
            });
            
            // 显示效率建议
            const productivityTips = document.getElementById('productivityTips');
            productivityTips.innerHTML = '';
            schedule.productivity_tips.forEach(tip => {
                const li = document.createElement('li');
                li.textContent = tip;
                productivityTips.appendChild(li);
            });
            
            // 显示AI洞察
            const aiInsights = document.getElementById('aiInsights');
            aiInsights.innerHTML = '';
            schedule.ai_insights.forEach(insight => {
                const li = document.createElement('li');
                li.textContent = insight;
                aiInsights.appendChild(li);
            });
            
            // 显示周目标
            const weeklyGoals = document.getElementById('weeklyGoals');
            weeklyGoals.innerHTML = '';
            schedule.weekly_goals.forEach(goal => {
                const li = document.createElement('li');
                li.textContent = goal;
                weeklyGoals.appendChild(li);
            });
            
            // 显示结果区域
            document.getElementById('scheduleResult').style.display = 'block';
        }
    </script>
</body>
</html>